package ext.opensource.netty.server.example.scanner;

import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;

public class Invoker {

	/**
	 * 方法
	 */
	private Method method;

	/**
	 * 目标对象
	 */
	private Object target;

	public static Invoker valueOf(final Method method, final Object target) {
		final Invoker invoker = new Invoker();
		invoker.setMethod(method);
		invoker.setTarget(target);
		return invoker;
	}

	/**
	 * 执行
	 * 
	 * @param paramValues
	 * @return
	 * @throws InvocationTargetException
	 * @throws IllegalArgumentException
	 * @throws IllegalAccessException
	 */
	public Object invoke(final Object... paramValues) {
		try {
			return method.invoke(target, paramValues);
		} catch (final IllegalAccessException e) {
			e.printStackTrace();
		} catch (final IllegalArgumentException e) {
			e.printStackTrace();
		} catch (final InvocationTargetException e) {
			e.printStackTrace();
		}
		return null;
	}

	public Method getMethod() {
		return method;
	}

	public void setMethod(final Method method) {
		this.method = method;
	}

	public Object getTarget() {
		return target;
	}

	public void setTarget(final Object target) {
		this.target = target;
	}
}
